package com.c.ctgproject.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.c.ctgproject.R
import com.c.ctgproject.base.BaseEmptyRecyclerViewAdapter
import com.c.ctgproject.entity.MaterialSellEntity
import com.c.ctgproject.mode.MyConstants
import com.c.ctgproject.ui.production.material.MaterialInputWeightActivity
import com.c.ctgproject.utils.handlerNull
import org.jetbrains.anko.startActivity

class MaterialInputWeightAdapter(private val context: Context, private val list: ArrayList<MaterialSellEntity.ListBean>) : BaseEmptyRecyclerViewAdapter<MaterialSellEntity.ListBean>(context, list) {
    override fun createViewHolder(parent: ViewGroup): RecyclerView.ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_material_input_weight_list, null, false)
        return MyViewHolder(view)
    }

    override fun handlerData(holder: RecyclerView.ViewHolder, position: Int) {
        if (holder is MyViewHolder) {
            val data = list[position]
            holder.mMaterialNameTV.text = data.materialName.handlerNull()
            holder.mMaterialNameLL.setOnClickListener {
                context.startActivity<MaterialInputWeightActivity>(
                    MyConstants.MATERIAL_NAME to data.materialName.handlerNull()
                )
            }
        }
    }

    inner class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val mMaterialNameLL: LinearLayout = view.findViewById(R.id.mMaterialNameLL)
        val mMaterialNameTV: TextView = view.findViewById(R.id.mMaterialNameTV)
    }

}